
#include "XMLWriter.h"

/** Write the document specified by document pointer to the filename given.
 * 
 * @param filename
 * The name of the file to write to.
 * 
 * @param tdoc
 * The XML document pointer to use to populate the file.
 * 
 * @return
 * Zero on success, non-zero on an error. */
int XMLWriter::xmlWrite(const char *filename, xmlDocPtr tdoc)
{
#ifdef XML_SAVE_WSNONSIG
   xmlSaveCtxtPtr svectxt = xmlSaveToFilename(filename, NULL, XML_SAVE_WSNONSIG);
#else
   xmlSaveCtxtPtr svectxt = xmlSaveToFilename(filename, NULL, 0);
#endif
   xmlSaveDoc(svectxt, tdoc);
   return (xmlSaveClose(svectxt) < 0);
}

/** Write the document specified by document pointer to the buffer given by
 * the xmlBufferPtr.
 * 
 * @param buffer
 * A pointer to the XML buffer object to write the XML document into.
 * 
 * @param tdoc
 * The XML document pointer to use to populate the buffer.
 * 
 * @return
 * Zero on success, non-zero on an error. */
int XMLWriter::xmlWrite(xmlBufferPtr buffer, xmlDocPtr tdoc)
{
#ifdef XML_SAVE_WSNONSIG
   xmlSaveCtxtPtr svectxt = xmlSaveToBuffer(buffer, NULL, XML_SAVE_WSNONSIG);
#else
   xmlSaveCtxtPtr svectxt = xmlSaveToBuffer(buffer, NULL, 0);
#endif
   xmlSaveDoc(svectxt, tdoc);
   return (xmlSaveClose(svectxt) < 0);
}
